package com.sc.nft.dao;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.sc.nft.entity.OrderGasDetail;
import com.sc.nft.enums.OrderGasTypeEnum;
import com.sc.nft.mapper.OrderGasDetailMapper;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import java.math.BigDecimal;
import java.util.Date;

/**
 * @author 刘国航
 * @desc
 * @since 2024/10/21 11:12
 */
@Slf4j
@Repository
public class OrderGasDetailDao extends ServiceImpl<OrderGasDetailMapper, OrderGasDetail> {

    /**
     * 根据订单查询
     *
     * @param orderId
     * @param orderNo
     * @param orderType
     * @return
     */
    public OrderGasDetail getByOrderIdNoType(Long orderId, String orderNo, OrderGasTypeEnum orderType) {
        LambdaQueryWrapper<OrderGasDetail> queryWrapper = new LambdaQueryWrapper<>();
        queryWrapper.eq(OrderGasDetail::getOrderId, orderId);
        queryWrapper.eq(OrderGasDetail::getOrderNo, orderNo);
        queryWrapper.eq(OrderGasDetail::getOrderType, orderType);
        queryWrapper.orderByDesc(OrderGasDetail::getId);
        queryWrapper.last("limit 1");
        return getOne(queryWrapper);
    }

    public BigDecimal getUnCountedBeforeDate(Date orderTime) {
        return baseMapper.getUnCountedBeforeDate(orderTime);
    }

    public Boolean updateCountedBeforeDate(Date orderTime) {
        return baseMapper.updateCountedBeforeDate(orderTime) > 0;
    }

    public BigDecimal getUnSettledBeforeDate(Date orderTime) {
        return baseMapper.getUnSettledBeforeDate(orderTime);
    }

    public Boolean updateSettledBeforeDate(Date orderTime) {
        return baseMapper.updateSettledBeforeDate(orderTime) > 0;
    }

}
